/* Copyright 2001,2002,2003 NAH6 BV
 * All Rights Reserved
 *
 *  $Header: /var/lib/cvs/secphone/ui/rng/sources/esrcAudioInput.h,v 1.3 2003/11/21 12:39:24 itsme Exp $
 *
 *
 */


#ifndef __ESRCAUDIOINPUT_H__

#include "fnaEntropySource.h"
#include "nhQueue.h"

#include <vector>

#include <Mmsystem.h>

typedef short sample_t;

typedef std::vector<sample_t> SampleVector;
typedef std::vector<SampleVector> SampleBufferList;
typedef std::vector<WAVEHDR> WaveHdrList;

class esrcAudioInput : public EntropySource {
public:
    esrcAudioInput();
    virtual ~esrcAudioInput();

    virtual void HandleSource();

    virtual bool IsPolledSource() const;

    virtual const char* name() const { return "esrcAudioInput"; }

    void StopAudioInput();
    bool StartAudioInput();

private:
        HWAVEIN  m_hwi;
        DWORD m_samplesperblock;
        DWORD m_samplerate;

        int m_nBlocks;  // nr of audio blocks to keep around
        WaveHdrList m_whlist;
        SampleBufferList m_bufferlist;

        bool m_bRunning;
        NHQueue<WAVEHDR*> m_queue;

        int m_nAudioBlocksProcessed;

    bool CopyInputBuffer( WAVEHDR *pwh);
    static void CALLBACK waveInProc(HWAVEIN hwi, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2);
    void HandleWaveCallback(UINT uMsg, WAVEHDR* pwh);
    bool UnPrepareInputBuffer( WAVEHDR *pwh );
    bool PrepareAndSubmitBuffer(int i);

};

#define __ESRCAUDIOINPUT_H__
#endif

